package com.sskj.mine.ui.fragment;


import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bulong.rudeness.RudenessScreenHelper;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseFragment;
import com.sskj.lib.mvchelper.ModelRx2DataSource;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.bean.RechargeListBean;
import com.sskj.mine.presenter.AssetRecordFragmentPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import io.reactivex.Flowable;

@Route(path = RConfig.MINE_FRAGMENT_ASSET_RECORD)//冲提币记录
public class AssetRecordFragment extends BaseFragment<AssetRecordFragmentPresenter> {
    @Autowired
    String code;
    @Autowired
    String type;
    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.coolRefreshView)
    CoolRefreshView coolRefreshView;
    private MVCCoolHelper<List<RechargeListBean>> mvcCoolHelper;

    @Override
    protected int getLayoutId() {
        return R.layout.mine_fragment_asset_record;
    }

    @Override
    public AssetRecordFragmentPresenter getPresenter() {
        return new AssetRecordFragmentPresenter();
    }

    @Override
    public void initView() {
        ARouter.getInstance().inject(this);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(getActivity())
                .setFirstDraw(false)
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 2))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.transparent)));
        SlimAdapter slimAdapter = SlimAdapter.create().register(R.layout.mine_recy_item_asset_record, new SlimInjector<RechargeListBean>() {
            @Override
            public void onInject(RechargeListBean data, IViewInjector injector, List payloads) {
                injector
                        .text(R.id.tvAddressTitle, type.equals("1") ? App.INSTANCE.getString(R.string.mineAssetRecordFragment1) : App.INSTANCE.getString(R.string.mineAssetRecordFragment2))
                        .text(R.id.tvNumTitle, type.equals("1") ? App.INSTANCE.getString(R.string.mineAssetRecordFragment4) : App.INSTANCE.getString(R.string.mineAssetRecordFragment5))
                        .text(R.id.tvSubmitTimeTitle, App.INSTANCE.getString(R.string.mineAssetRecordFragment6))
                        .text(R.id.tvCheckTimeTitle, App.INSTANCE.getString(R.string.mineAssetRecordFragment7))
                        .text(R.id.tvAddress, data.getWalletAddr())
                        .text(R.id.tvNum, data.getUsdFee())
                        .text(R.id.tvSubmitTime, data.getCreateTime())
                        .text(R.id.tvCheckTime, data.getInspectTime())
                        .textColor(R.id.tvStatus, getResources().getColor(data.getInspectStatus() == 3 ? R.color.mine_87a : data.getInspectStatus() == 2 ? R.color.mine_ff4 : data.getInspectStatus() == 1 ? R.color.commonTextEEE : R.color.mine_87a))
                        .text(R.id.tvStatus, data.getInspectStatus() == 3 ? App.INSTANCE.getString(R.string.mineAssetRecordFragment8) : data.getInspectStatus() == 2 ? App.INSTANCE.getString(R.string.mineAssetRecordFragment9) : data.getInspectStatus() == 1 ? App.INSTANCE.getString(R.string.mineAssetRecordFragment10) : App.INSTANCE.getString(R.string.mineAssetRecordFragment8));

            }
        }).attachTo(recyclerView).updateData(new ArrayList());
        ModelRx2DataSource<RechargeListBean> dataSource = new ModelRx2DataSource<>(new ModelRx2DataSource.OnLoadSource() {
            @Override
            public Flowable<List<RechargeListBean>> loadSource(int page) {
                return mPresenter.getAssetRecord(page, 10, type, code);
            }
        }, 10);
        mvcCoolHelper = new MVCCoolHelper<>(coolRefreshView);
        mvcCoolHelper.setDataSource(dataSource);
        mvcCoolHelper.setAdapter(slimAdapter);
        mvcCoolHelper.refresh();
    }


}
